//
//  DelButton.m
//  DuBai
//
//  Created by darktm on 14-3-14.
//  Copyright (c) 2014年 darktm. All rights reserved.
//

#import "DelButton.h"

@implementation DelButton

@synthesize delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        UIColor *c = [UIColor RGBWithR:182 g:133 b:99];
        
        self.layer.borderColor = [c CGColor];
        self.layer.borderWidth = 1.0f;
        self.layer.cornerRadius = 8.0f;
        self.font = [UIFont systemFontOfSize:13.0f];
        
        self.userInteractionEnabled = YES;
        self.textColor = c;
    }
    return self;
}


-(void)setCutstomerTitle:(NSString *)title{
    
//    assert(title);
    self.text = [@"  " stringByAppendingString:title];
    
    float rightInset = 12.0f;
    float centerInset = 6.0f;
    float wideDel = 15;
    
    float titleWide = [title sizeWithFont:self.font].width;
    
    CGRect frame = self.frame;
    frame.size.width = + rightInset + centerInset + titleWide + wideDel;
    self.frame = frame;
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(titleWide  + centerInset + 6, (self.bounds.size.height - wideDel) / 2, wideDel, wideDel)];
    [btn setImage:[UIImage imageNamed:@"home_filtrate_btn_del.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(on_btn_del:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
}

-(void)on_btn_del:(UIButton *)btn{
    NSInteger tag = btn.superview.tag;
    btn.tag = tag;
    if(delegate && [delegate respondsToSelector:@selector(didDelBtn:)])
        [delegate didDelBtn:self];
}

@end
